package com.zhonghan.recharge.service.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhonghan.common.bean.Result;
import com.zhonghan.common.enums.ResultStatus;
import com.zhonghan.common.utils.StringUtils;
import com.zhonghan.recharge.dao.OilCustomerOrderDao;
import com.zhonghan.recharge.dao.OilCustomerReleaseDao;
import com.zhonghan.recharge.pojo.OilCustomerOrder;
import com.zhonghan.recharge.pojo.OilCustomerRelease;
import com.zhonghan.recharge.service.OilCustomerOrderService;
import com.zhonghan.recharge.service.OilCustomerReleaseService;
@Service
public class OilCustomerOrderServiceImpl implements OilCustomerOrderService{
    @Autowired
    private OilCustomerOrderDao oilCustomerOrderDao;
    @Autowired
    private OilCustomerReleaseDao oilCustomerReleaseDao;
    @Override
    public long getOilCustomerOrderRowCount(){
        return oilCustomerOrderDao.getOilCustomerOrderRowCount();
    }
    @Override
    public List<OilCustomerOrder> selectOilCustomerOrder(){
        return oilCustomerOrderDao.selectOilCustomerOrder();
    }
    @Override
    public List<OilCustomerOrder> selectOilCustomerOrderByObj(OilCustomerOrder obj){
        return oilCustomerOrderDao.selectOilCustomerOrderByObj(obj);
    }
    @Override
    public OilCustomerOrder selectOilCustomerOrderById(Integer id){
         OilCustomerOrder selectOilCustomerOrderById = oilCustomerOrderDao.selectOilCustomerOrderById(id);
         return selectOilCustomerOrderById;
    }
    @Override
    public int insertOilCustomerOrder(OilCustomerOrder value){
        return oilCustomerOrderDao.insertOilCustomerOrder(value);
    }
    @Override
    public int insertNonEmptyOilCustomerOrder(OilCustomerOrder value){
        return oilCustomerOrderDao.insertNonEmptyOilCustomerOrder(value);
    }
    @Override
    public int insertOilCustomerOrderByBatch(List<OilCustomerOrder> value){
        return oilCustomerOrderDao.insertOilCustomerOrderByBatch(value);
    }
    @Override
    public int deleteOilCustomerOrderById(Integer id){
        return oilCustomerOrderDao.deleteOilCustomerOrderById(id);
    }
    @Override
    public int updateOilCustomerOrderById(OilCustomerOrder enti){
        return oilCustomerOrderDao.updateOilCustomerOrderById(enti);
    }
    @Override
    public int updateNonEmptyOilCustomerOrderById(OilCustomerOrder enti){
        return oilCustomerOrderDao.updateNonEmptyOilCustomerOrderById(enti);
    }

    public OilCustomerOrderDao getOilCustomerOrderDao() {
        return this.oilCustomerOrderDao;
    }

    public void setOilCustomerOrderDao(OilCustomerOrderDao oilCustomerOrderDao) {
        this.oilCustomerOrderDao = oilCustomerOrderDao;
    }
    /**
     * 通过名字查询自己的信息
     * @param customerName
     * @param pageNum
     * @param pageSize
     * @return
     */
    public Result selectOilCustomerOrderByName(String customerName,Integer pageNum,Integer pageSize){
    	pageNum = pageNum == null ? 0 : pageNum;
    	pageSize = pageSize == null ? 0 : pageSize;
    	
    	OilCustomerOrder oilCustomerOrder = new OilCustomerOrder();
    	
    	if(StringUtils.isNotEmpty(customerName)){
    		oilCustomerOrder.setCustomerName(customerName);
    	}
    	oilCustomerOrder.setOrderBy("create_time");
    	oilCustomerOrder.setSortBy("desc");
    	
    	Result result = new Result();
		try{
			PageHelper.startPage(pageNum, pageSize);
			List<OilCustomerOrder> selectOilByName = oilCustomerOrderDao.selectOilByName(oilCustomerOrder);
			PageInfo<OilCustomerOrder> pageInfo = new PageInfo<>(selectOilByName);
			result.setCode(ResultStatus.SUCCESS.getCode());
			result.setData(pageInfo);
			
		}catch(Exception e) {
			e.printStackTrace();
			result.setCode(ResultStatus.BUSYNESS.getCode());
			result.setMsg(ResultStatus.BUSYNESS.getDescription());
		}
    	return result;
    }
    
}